home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 214 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.9 KB

  1. From: Valentin Bonnard <bonnardv@pratique.fr>
  2. Message-ID: <4eqr6b$778@s3.iway.fr>
  3. X-Original-Date: 1 Feb 1996 16:53:30 GMT
  4. Path: in2.uu.net!bounce-back
  5. Date: 01 Feb 96 17:10:01 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Return-Path: <news@iway.fr>
  8. Newsgroups: comp.std.c++
  9. Subject: Re: Give operator. a chance
  10. Organization: Internet Way
  11. References: <3102AD11.1663@et.se> <4e0pj1$rq6@news.bridge.net> <9601260532.14152@mulga.cs.mu.OZ.AU>
  12. X-Mailer: Mozilla 1.1N (Macintosh; I; 68K)
  13. X-Url: news:9601260532.14152@mulga.cs.mu.OZ.AU
  14. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  15.     iQBFAgUBMRD0FOEDnX0m9pzZAQFgAAF9GPrmSgpuprhbtVKUoXv6Cf+OdNHN1xZY
  16.     vZfpf9rqdE3p0N/9oGkp+Ky4E9Z1VO70
  17.     =3Ps8
  18.  
  19. First of all, I suppose there is no difference bewten A + B, A.operator+ (B)
  20. and A.plus (B) when operator+ is defined as plus.
  21.  
  22. Suppose first you overload operator+, then you overload operator. in MyClass:
  23.  
  24. class MyClass {
  25. private:
  26.    AnnotherClass* theOtherClass;
  27. public:
  28.    AnnotherClass operator. ();
  29.    MyClass       operator+ (int);
  30.    void          Something_only_defined_in_MyClass ();
  31. };
  32.  
  33. MyClass A;
  34.  
  35. A + 2; is equivalent with A.operator (2) and (A.operator.).operator (2)
  36.  
  37. You can't even write (&A)->Something_only_defined_in_MyClass () in order to
  38. access Something_only_defined_in_MyClass (which is only defined for MyClass):
  39. (&A)->a_member is equivalent with ((A.operator.).operator&)->a_member.
  40.  
  41. How can yu access Something_only_defined_in_MyClass ?
  42.  
  43. If operator. return theOtherClass, why don't you just write:
  44. AnnotherClass*    theOtherClass;
  45.  
  46. theOtherClass + 2;
  47.  
  48. Note that A.m _is equivalent_ (provided that operator. is not overloaded in 
  49. AnnotherClass) with (&A)->m.
  50.  
  51. Valentin Bonnard
  52. bonnardv@pratique.fr
  53. ---
  54. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  55.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  56.   is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
  57.